var Api = require("../../../api/method.js");
var app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    currentData: 0,
    withdrawlist:"",
    openBank:"",
    bankCode:"",
    amount:"",
    accountBalance:""
  },
  //获取当前滑块的index
  bindchange: function (e) {
    const that = this;
    that.setData({
      currentData: e.detail.current
    })
  },
  //点击切换，滑块index赋值
  checkCurrent: function (e) {
    const that = this;
    if (that.data.currentData === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentData: e.target.dataset.current
      })
    }
  },
  //添加银行卡
  addbank:function(e){
    wx.navigateTo({
      url:"/pages/Salesman/addwithdraw/addwithdraw",
    })
  },
  //银行卡列表
  QueryBank:function(e){
    let that = this;
    let list = {
    };
    Api.queryBank(list, function (err, res) {
      console.log(res.data)
      if (res.data.code == 1) {
        if(res.data.data == null){
            console.log("没有数据")
        }else{
        that.setData({
          withdrawlist: 1,
          openBank: res.data.data.openBank,
          bankCode: res.data.data.bankCode
        })
        }
      }
    }); 
  },
  //提现金额
  getAmount:function(e){
    this.setData({
      amount:e.detail.value
    })
  },
  //全部提现
  allbindtap:function(e){
    if (this.data.accountBalance == "undefined"){
      this.setData({
        amount:0
      })
    }else{
      this.setData({
        amount: this.data.accountBalance
      })
    }
  },
  //确认提现
  tixian:function(e){
    let that = this;
    if(that.data.amount == ""){
      wx.showToast({
        icon: "none",
        duration: 1500,
        title: "请输入提现金额"
      })
      return
    }else if(that.data.amount == 0){
      wx.showToast({
        icon: "none",
        duration: 1500,
        title: "请输入提现金额"
      })
      return
    }
    let list = {
      amount:that.data.amount
    };
    Api.cashOut(list, function (err, res) {
      console.log(res.data)
      if (res.data.code == 1) {
        wx.showToast({
          icon: "none",
          duration: 1500,
          title: `${res.data.data}`
        })
        wx.redirectTo({
          url: '/pages/Salesman/me/me',
        })
      }else{
        wx.showToast({
          icon: "none",
          duration: 1500,
          title: `${res.data.message}`
        })
      }
    }); 
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options);
    this.setData({
      accountBalance: options.accountBalance
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.QueryBank();
    //加载本页面的tabBar样式
    app.editTabBar2();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})